using UnityEngine;
using System.Collections;

public class PlayerActivateSwitchState : State<PlayerControl>
{
    #region Singleton

    private static PlayerActivateSwitchState instance = new PlayerActivateSwitchState();
    public static PlayerActivateSwitchState Instance { get { return instance; } }
    private PlayerActivateSwitchState() { }

    #endregion
    
    #region State

    public override void OnEnter(PlayerControl behaviour)
    {
        behaviour.doActionOnTargetPosition = false;
    }

    public override void OnUpdate(PlayerControl behaviour)
    {
        Quaternion origin = behaviour.transform.rotation;
        Quaternion destination = Quaternion.LookRotation(-behaviour.switchControl.transform.forward);
        behaviour.transform.rotation = Quaternion.Slerp(origin, destination, behaviour.dirChangeSpeed);
        behaviour.Controller.updateRotation = true;

        if (Quaternion.Angle(origin, destination) == 0)
            behaviour.switchControl.Execute(behaviour);
        //TODO hacer animacion de activar switch
        //behaviour.playerPrefab.animation.CrossFade(AnimationConstants.PLAYER_ACTIVATE);
    }

    public override void OnExit(PlayerControl behaviour)
    {
        
    }

    public override void OnAction(string name, PlayerControl behaviour, object value)
    {
    }

    #endregion
}
